package Java9_16;

public class Run extends Thread {
    private int speed;//秒/100m
    private MingCi c;

    public Run(String name, int speed, MingCi c) {
        super(name);
        this.speed = speed;
        this.c = c;
    }

    @Override
    public void run() {
        int length = 1000;
        for (int i = 0; i < 10; i++) {
            System.out.println(getName() + "跑了" + (i + 1) * 100 + "米");
            try {
                sleep(speed);
                length -= 100;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        synchronized (c){
            if (length == 0) {
                System.out.println(getName() + " 第" + c.getNum() + "名");
                c.add();
            }
        }
    }
}
